import re
import os

path = r"C:/CloudMusic/电台节目/"    # 目标路径
 
"""os.listdir(path) 操作效果为 返回指定路径(path)文件夹中所有文件名"""

filename_list = os.listdir(path)  # 扫描目标路径的文件,将文件名存入列表

reE=r".+- "

for item in filename_list:

	repStr = re.sub(reE, 'f', item)
	searchObj = re.search(r"\d+(?=\.{0,2})",repStr)
	repStr = re.sub(r"\d+\.+[ ]*", str(int(searchObj.group())), repStr)
	used_name = path + item
	new_name = path + repStr
	os.rename(used_name,new_name)
	print("文件%s重命名成功,新的文件名为%s" %(used_name,new_name))
